<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        // 将数据展示成目录树的样子
        const json = [{
                title: '一',
                key: '1',
                children: [{
                    title: '三',
                    key: '3',
                    children: []
                }]
            },
            {
                title: '二',
                key: '2',
                children: [{
                    title: '四',
                    key: '4',
                    children: []
                }]
            },
        ]


        const dfs = (data) => {
            return `<div>
                    <div>${data.title}</div>
                    
                </div>`
        }

        const init = (json) => {
            let content = '<div>'
            json.forEach(item => {
                content += dfs(item)
            })

            content+='</div>'
            return content
        }

        console.log(init(json))
        document.body.innerHTML = (init(json))
    </script>
</body>

</html>